export default class Common extends Laya.Script {
    static requestBaseUrl = "https://c.leaf-tech.net"
    static platform = "toutiao"
    // static platform = "weixin"
    static timeArray:any = []//定时器执行域

    static appId = 6
    static toutiaoAppName = "";//头条宿主APP名称

    //获取授权按钮事件信息
    static lastAuthCallbackEventName = "";
    static lastAuthCallbackEventArgs = new Array();

    //激励视频事件回调
    static lastRewardedVideoEventName = "";
    static lastRewardedVideoEventArgs = new Array();

    //授权的按钮列表
    public static wxAuthButtonArr = new Array();

    //分享好友，内容文本
    static shareTitle = ""

    //音乐状态
    static musicChannel: any;

    static lastVideoStartTime = null;//录屏的开始时间
    static lastVideoSecond = 0;//录屏的时长
    static lastVideoPath;//最后分享是视频路径

    static transferLevel(level: number) {
        let str = "";
        switch (level) {
            case 0:
                str = "旅途才刚刚开始，神秘的金星等你穿越";
                break;
            case 1:
                str = "站在金星，望着地球，下一站在等待着你到来";
                break;
            case 2:
                str = "坑洼的水星，一刻都不想停留，需继续努力往下个星球出发。";
                break;
            case 3:
                str = "穿越了火星，人类的探索仍未结束";
                break;
            case 4:
                str = "停留在质量最重的木星，探索的任务依旧是沉甸甸的。";
                break;
            case 5:
                str = "到达了与众不同的土星，充满神秘而又炫目夺人";
                break;
            case 6:
                str = "最远的天王星，我们的脚步仍未停止";
                break;
            case 7:
                str = "冷酷的海王星，却藏着探索的热情与欲望";
                break;
            case 8:
                str = "人类终究停留在了浩瀚的宇宙，往下一个宇宙出发。";
                break;

        }
        return str;
    }


    static getCacheItem(key): string {
        if (Laya.LocalStorage.getItem(key) != "0" && (Laya.LocalStorage.getItem(key) == "" || Laya.LocalStorage.getItem(key) == undefined)) {
            return null;
        } else {
            return Laya.LocalStorage.getItem(key);
        }
    }

    static setCacheItem(key, value): void {

        Laya.LocalStorage.setItem(key, value);
    }

    static getNowDate(): string {
        const date = new Date();
        let month: string | number = date.getMonth() + 1;
        let strDate: string | number = date.getDate();

        if (month <= 9) {
            month = "0" + month;
        }

        if (strDate <= 9) {
            strDate = "0" + strDate;
        }

        return date.getFullYear() + "-" + month + "-" + strDate;
    }

    /**
     * 圆形遮罩
     */
    public static transferImageToCircle(img: any) {
        let x = img.width / 2;
        let y = img.height / 2;
        var mask = new Laya.Sprite();
        //画一个圆形的遮罩区域
        mask.graphics.drawCircle(0, 0, x, "#f00");
        mask.pos(x, y);
        img.mask = mask;
        // console.log(mask)
        // console.log(img);
        return img;
    }

    /**
     * 转空字符
     */
    public static transferNoNullValue(n: any, defaultValue: any) {
        if (typeof (n) == undefined || n == null) {
            return defaultValue;
        } else {
            return n;
        }
    }

    /**
     * 勾股定理
     */
    static pythagorean(x0: number, y0: number, x: number, y: number) {
        let a = y - y0
        let b = x - x0
        let line = Math.sqrt(a * a + b * b)
        return line
    }

    /**
     * 获取当前时间
     */
    static getCurrentTime() {
        return Date.parse((new Date()).toUTCString());
    }

    /**
     * 随机弹插屏广告
     */
    static getRandomAd(num: number = 0.35) {
        if (this.toutiaoAppName === "Toutiao") {
            let randomNum = Math.random();
            if (randomNum > num) {
                Laya.stage.event("ShowInterstitialAd");//展示插屏广告
            }
        }
    }


}